/*
   Copyright 2009 Bégaudeau Stéphane

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package faneclipse.editors;

import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IPredicateRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.MultiLineRule;
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
import org.eclipse.jface.text.rules.Token;

/**
 * This class is in charge of scanning the code and creating the different
 * partition within the code. 
 * There are 3 partitions : single-line comments (//), multi-line comments (\/* *\/)
 * and FanDoc comments (**).
 * @author stephane
 */
public class FanPartitionScanner extends RuleBasedPartitionScanner {
	/**
	 * The name of the partition of single-line comments.
	 */
	public static final String FAN_COMMENT_SINGLE_LINE = "__fan_comment_single_line";
	/**
	 * The name of the partition of multi-line comments.
	 */
	public static final String FAN_COMMENT_MULTI_LINE = "__fan_comment_multi_line";
	/**
	 * The name of the partition of FanDoc comments.
	 */
	public static final String FAN_COMMENT_FAN_DOC = "__fan_comment_fan_doc";
	/**
	 * The array of the differents partition's types.
	 */
	public static final String[] FAN_PARTITION_TYPES = new String[] {FAN_COMMENT_SINGLE_LINE,
																	FAN_COMMENT_MULTI_LINE,
																	FAN_COMMENT_FAN_DOC};
	
	/**
	 * The constructor.
	 */
	public FanPartitionScanner() {
		super();
		IToken fanCommentSingleLine = new Token(FAN_COMMENT_SINGLE_LINE);
		IToken fanCommentMultiLine = new Token(FAN_COMMENT_MULTI_LINE);
		IToken fanCommentFanDoc = new Token(FAN_COMMENT_FAN_DOC);
		IPredicateRule[] rules = new IPredicateRule[] {new EndOfLineRule("//", fanCommentSingleLine),
														new MultiLineRule("/*", "*/", fanCommentMultiLine),
														new EndOfLineRule("**", fanCommentFanDoc)};
		setPredicateRules(rules);
	}
}
